package com.je;

import com.alibaba.fastjson.JSON;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xddf.usermodel.PresetColor;
import org.apache.poi.xddf.usermodel.XDDFColor;
import org.apache.poi.xddf.usermodel.XDDFSolidFillProperties;
import org.apache.poi.xddf.usermodel.chart.AxisCrossBetween;
import org.apache.poi.xddf.usermodel.chart.AxisCrosses;
import org.apache.poi.xddf.usermodel.chart.AxisPosition;
import org.apache.poi.xddf.usermodel.chart.AxisTickLabelPosition;
import org.apache.poi.xddf.usermodel.chart.AxisTickMark;
import org.apache.poi.xddf.usermodel.chart.BarDirection;
import org.apache.poi.xddf.usermodel.chart.BarGrouping;
import org.apache.poi.xddf.usermodel.chart.ChartTypes;
import org.apache.poi.xddf.usermodel.chart.LegendPosition;
import org.apache.poi.xddf.usermodel.chart.XDDFBarChartData;
import org.apache.poi.xddf.usermodel.chart.XDDFChart;
import org.apache.poi.xddf.usermodel.chart.XDDFChartAxis;
import org.apache.poi.xddf.usermodel.chart.XDDFChartLegend;
import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory;
import org.apache.poi.xddf.usermodel.chart.XDDFDoughnutChartData;
import org.apache.poi.xddf.usermodel.chart.XDDFLineChartData;
import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
import org.apache.poi.xddf.usermodel.chart.XDDFPieChartData;
import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
import org.apache.poi.xwpf.usermodel.XWPFChart;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBarChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBarSer;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTDLbls;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTHoleSize;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLineSer;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
import org.openxmlformats.schemas.drawingml.x2006.chart.STDLblPos;
import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;

public class WordUtil {

    private static final List<XDDFColor> colorList = new ArrayList<>();
    public static boolean varyColors = false;

    static {
        colorList.add(XDDFColor.from(PresetColor.CORNFLOWER_BLUE));
        colorList.add(XDDFColor.from(PresetColor.ORANGE));
        colorList.add(XDDFColor.from(PresetColor.GRAY));
        colorList.add(XDDFColor.from(PresetColor.GOLD));
        colorList.add(XDDFColor.from(PresetColor.BLUE));
        colorList.add(XDDFColor.from(PresetColor.GREEN));
        colorList.add(XDDFColor.from(PresetColor.AQUA));
        colorList.add(XDDFColor.from(PresetColor.AQUAMARINE));
        colorList.add(XDDFColor.from(PresetColor.BISQUE));
        colorList.add(XDDFColor.from(PresetColor.CHOCOLATE));
        colorList.add(XDDFColor.from(PresetColor.CORAL));
        colorList.add(XDDFColor.from(PresetColor.CYAN));
        colorList.add(XDDFColor.from(PresetColor.KHAKI));
        colorList.add(XDDFColor.from(PresetColor.TURQUOISE));
        colorList.add(XDDFColor.from(PresetColor.DARK_BLUE));
    }

    public static void main(String[] args) throws IOException, InvalidFormatException {
        LinkedHashMap<String, Double> map = new LinkedHashMap<>();
        LinkedHashMap<String, Double> map1 = new LinkedHashMap<>();
        map.put("测试", 111d);
        map.put("测试1", 222d);
        map.put("测试333", 4546d);
        map.put("测试委屈", 34535d);
        map.put("测认为分割为", 2244d);
        map.put("测试测温官方", 334d);
        map1.put("测试", 112d);
        map1.put("测试1", 225d);
        map1.put("测试333", 856d);
        map1.put("测试委屈", 2435d);
        map1.put("测认为分割为", 224d);
        map1.put("测试测温官方", 3324d);
        Map<String, LinkedHashMap<String, Double>> groupMap = new HashMap<>();
        Map<String, LinkedHashMap<String, Double>> groupMap1 = new HashMap<>();
        groupMap.put("1", map);
        groupMap1.put("2", map1);
        System.out.println(JSON.toJSONString(groupMap));

        XWPFDocument document = new XWPFDocument();
        XWPFChart chart = document.createChart(XDDFChart.DEFAULT_WIDTH * 10,
                XDDFChart.DEFAULT_HEIGHT * 5);
        getColumnChart(chart, "柱状图", groupMap);
        getLineChart(chart, "", groupMap, "RIGHT");
        getLineChart(chart, "", groupMap1, "LEFT");
        chart = document.createChart(XDDFChart.DEFAULT_WIDTH * 10,
                XDDFChart.DEFAULT_HEIGHT * 5);
        getBarChart(chart, "条形图", groupMap);
        chart = document.createChart(XDDFChart.DEFAULT_WIDTH * 10,
                XDDFChart.DEFAULT_HEIGHT * 5);
        getStackedChart(chart, "堆积图", groupMap);
        chart = document.createChart(XDDFChart.DEFAULT_WIDTH * 10,
                XDDFChart.DEFAULT_HEIGHT * 5);
        getPieChart(chart, "饼图", map);
        chart = document.createChart(XDDFChart.DEFAULT_WIDTH * 10,
                XDDFChart.DEFAULT_HEIGHT * 5);
        getDonutChart(chart, "环形图", map);
        chart = document.createChart(XDDFChart.DEFAULT_WIDTH * 10,
                XDDFChart.DEFAULT_HEIGHT * 5);
        getLineChart(chart, "折线图", groupMap, "LEFT");

        FileOutputStream stream = new FileOutputStream("word.docx");
        document.write(stream);
        stream.close();
    }

    public static void putColorList(List<XDDFColor> colors) {
        colorList.addAll(colors);
    }

    public static void getBarChart(XWPFChart chart, String chartTitle,
                                   Map<String, LinkedHashMap<String, Double>> groupMap) {
        XDDFChartAxis bottomAxis = chart.createCategoryAxis(AxisPosition.LEFT);
//        bottomAxis.setVisible(false);
//        bottomAxis.setTickLabelPosition(AxisTickLabelPosition.NONE);
        XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.BOTTOM);
        leftAxis.setCrossBetween(AxisCrossBetween.BETWEEN);

        XDDFBarChartData bar = (XDDFBarChartData) chart.createData(ChartTypes.BAR, bottomAxis, leftAxis);
        int i = 0;
        for (Entry<String, LinkedHashMap<String, Double>> entry : groupMap.entrySet()) {
            Map<String, Double> map = entry.getValue();
            String[] categories = map.keySet().toArray(new String[0]);
            Double[] values = map.values().toArray(new Double[0]);
            int numOfPoints = categories.length;
            String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));
            String valuesDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 1, 1));
            XDDFDataSource<?> categoriesData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange, 0);
            XDDFNumericalDataSource<? extends Number> valuesData = XDDFDataSourcesFactory.fromArray(values, valuesDataRange, 1);
            XDDFBarChartData.Series series = (XDDFBarChartData.Series) bar.addSeries(categoriesData, valuesData);
            series.setTitle(entry.getKey(), null);
            XDDFSolidFillProperties fill = new XDDFSolidFillProperties(colorList.get(i));
            //条形图，填充颜色
            series.setFillProperties(fill);
            i++;
            if (i >= colorList.size()) {
                i = 0;
            }
        }
        bar.setVaryColors(varyColors);
        bar.setBarDirection(BarDirection.BAR);
        chart.plot(bar);

        XDDFChartLegend legend = chart.getOrAddLegend();
        legend.setPosition(LegendPosition.BOTTOM);
        legend.setOverlay(false);

        chart.setTitleText(chartTitle);
        //取消标题粗体
        chart.getTitle().getBody().getXmlObject().getPArray(0).getRArray(0).getRPr().setSz(1400);
        chart.getTitle().getBody().getXmlObject().getPArray(0).getRArray(0).getRPr().setB(false);
        chart.setTitleOverlay(false);
        chart.setAutoTitleDeleted(false);
    }

    public static void getStackedChart(XWPFChart chart, String chartTitle,
                                       Map<String, LinkedHashMap<String, Double>> groupMap) {
        XDDFChartAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
//        bottomAxis.setVisible(false);
//        bottomAxis.setTickLabelPosition(AxisTickLabelPosition.NONE);
        XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
        leftAxis.setCrossBetween(AxisCrossBetween.BETWEEN);
        XDDFBarChartData bar = (XDDFBarChartData) chart.createData(ChartTypes.BAR, bottomAxis, leftAxis);
        int i = 0;
        for (Entry<String, LinkedHashMap<String, Double>> entry : groupMap.entrySet()) {
            Map<String, Double> map = entry.getValue();
            String[] categories = map.keySet().toArray(new String[0]);
            Double[] values = map.values().toArray(new Double[0]);
            int numOfPoints = categories.length;
            String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));
            String valuesDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 1, 1));
            XDDFDataSource<?> categoriesData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange, 0);
            XDDFNumericalDataSource<? extends Number> valuesData = XDDFDataSourcesFactory.fromArray(values, valuesDataRange, 1);
            XDDFBarChartData.Series series = (XDDFBarChartData.Series) bar.addSeries(categoriesData, valuesData);
            series.setTitle(entry.getKey(), null);
            XDDFSolidFillProperties fill = new XDDFSolidFillProperties(colorList.get(i));
            //条形图，填充颜色
            series.setFillProperties(fill);
            i++;
            if (i >= colorList.size()) {
                i = 0;
            }
        }

        bar.setVaryColors(varyColors);
        bar.setBarDirection(BarDirection.COL);
        bar.setBarGrouping(BarGrouping.STACKED);// 叠加柱状图
        bar.setOverlap((byte) 100);// 满值叠加柱子才不会错位
        bar.setGapWidth(1000);
        chart.plot(bar);

        XDDFChartLegend legend = chart.getOrAddLegend();
        legend.setPosition(LegendPosition.BOTTOM);
        legend.setOverlay(false);

        chart.setTitleText(chartTitle);
        chart.setTitleOverlay(false);
        chart.setAutoTitleDeleted(false);
    }


    public static void getColumnChart(XWPFChart chart, String chartTitle,
                                      Map<String, LinkedHashMap<String, Double>> groupMap) {
        XDDFChartAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
//        bottomAxis.setVisible(true);
        bottomAxis.setTickLabelPosition(AxisTickLabelPosition.LOW);

        XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
        leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
//        leftAxis.getOrAddMajorGridProperties().getXmlObject().addNewLn().setW(1);
        leftAxis.setMajorTickMark(AxisTickMark.NONE);//取消X轴的标刻度
        leftAxis.setCrossBetween(AxisCrossBetween.BETWEEN);
        leftAxis.crossAxis(bottomAxis);
        bottomAxis.crossAxis(leftAxis);
        XDDFBarChartData bar = (XDDFBarChartData) chart.createData(ChartTypes.BAR, bottomAxis, leftAxis);
        int i = 0;
        for (Entry<String, LinkedHashMap<String, Double>> entry : groupMap.entrySet()) {
            Map<String, Double> map = entry.getValue();
            String[] categories = map.keySet().toArray(new String[0]);
            Double[] values = map.values().toArray(new Double[0]);
            int numOfPoints = categories.length;
            String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));
            String valuesDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 1, 1));
            XDDFDataSource<?> categoriesData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange, 0);
            XDDFNumericalDataSource<? extends Number> valuesData = XDDFDataSourcesFactory.fromArray(values, valuesDataRange, 1);
            XDDFBarChartData.Series series = (XDDFBarChartData.Series) bar.addSeries(categoriesData, valuesData);
            series.setTitle(entry.getKey(), null);
            XDDFSolidFillProperties fill = new XDDFSolidFillProperties(colorList.get(i));
            //条形图，填充颜色
            series.setFillProperties(fill);
            if (i++ >= colorList.size()) {
                i = 0;
            }
        }
        bar.setVaryColors(varyColors);
        bar.setBarDirection(BarDirection.COL);
//        bar.setGapWidth(1000);
        CTPlotArea plotArea = chart.getCTChart().getPlotArea();
        chart.plot(bar);
        for (CTBarChart ctBarChart : plotArea.getBarChartList()) {
            for (CTBarSer ctBarSer : ctBarChart.getSerArray()) {
                ctBarSer.addNewDLbls();
                ctBarSer.getDLbls().addNewShowVal().setVal(true);
                ctBarSer.getDLbls().addNewShowLegendKey().setVal(false);
                ctBarSer.getDLbls().addNewShowCatName().setVal(false);
                ctBarSer.getDLbls().addNewShowSerName().setVal(false);
                ctBarSer.getDLbls().addNewDLblPos().setVal(STDLblPos.IN_END);
            }
        }
        CTValAx catAy = chart.getCTChart().getPlotArea().getValAxArray(0);
        // 设置图表背后的网格线
        CTLineProperties ctLine = catAy.addNewMajorGridlines().addNewSpPr().addNewLn();
        ctLine.addNewPrstDash().setVal(STPresetLineDashVal.DASH);

        XDDFChartLegend legend = chart.getOrAddLegend();
        legend.setPosition(LegendPosition.BOTTOM);
        legend.setOverlay(false);

        chart.setTitleText(chartTitle);
        chart.getTitle().getBody().getXmlObject().getPArray(0).getRArray(0).getRPr().setSz(1400);
        chart.getTitle().getBody().getXmlObject().getPArray(0).getRArray(0).getRPr().setB(false);
        chart.setTitleOverlay(false);
        chart.setAutoTitleDeleted(false);
    }

    public static void getDonutChart(XWPFChart chart, String chartTitle, Map<String, Double> map) {
        XDDFChartAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
//        bottomAxis.setVisible(false);
        XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);

        String[] categories = map.keySet().toArray(new String[0]);
        Double[] values = map.values().toArray(new Double[0]);
        int numOfPoints = categories.length;
        String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));
        String valuesDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 1, 1));
        XDDFDataSource<?> categoriesData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange, 0);
        XDDFNumericalDataSource<? extends Number> valuesData = XDDFDataSourcesFactory.fromArray(values, valuesDataRange, 1);

        XDDFDoughnutChartData bar = (XDDFDoughnutChartData) chart.createData(ChartTypes.DOUGHNUT, bottomAxis, leftAxis);
        bar.addSeries(categoriesData, valuesData);

        bar.setVaryColors(varyColors);
        chart.plot(bar);

        XDDFChartLegend legend = chart.getOrAddLegend();
        legend.setPosition(LegendPosition.BOTTOM);
        legend.setOverlay(false);

        chart.setTitleText(chartTitle);
        chart.getTitle().getBody().getXmlObject().getPArray(0).getRArray(0).getRPr().setSz(1400);
        chart.getTitle().getBody().getXmlObject().getPArray(0).getRArray(0).getRPr().setB(false);
        chart.setTitleOverlay(false);
        chart.setAutoTitleDeleted(false);

        //设置环的大小【这里不设置的话  就是个饼图了】
        CTHoleSize holeSize = chart.getCTChart().getPlotArea().getDoughnutChartArray(0).addNewHoleSize();
        holeSize.setVal((short) 60);

    }

    public static void getPieChart(XWPFChart chart, String chartTitle, Map<String, Double> map) {
        XDDFChartAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
//        bottomAxis.setVisible(false);
        XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);

        String[] categories = map.keySet().toArray(new String[0]);
        Double[] values = map.values().toArray(new Double[0]);
        int numOfPoints = categories.length;
        String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));
        String valuesDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 1, 1));
        XDDFDataSource<?> categoriesData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange, 0);
        XDDFNumericalDataSource<? extends Number> valuesData = XDDFDataSourcesFactory.fromArray(values, valuesDataRange, 1);

        XDDFPieChartData bar = (XDDFPieChartData) chart.createData(ChartTypes.PIE, bottomAxis, leftAxis);
        bar.addSeries(categoriesData, valuesData);

        bar.setVaryColors(varyColors);
        chart.plot(bar);

        XDDFChartLegend legend = chart.getOrAddLegend();
        legend.setPosition(LegendPosition.BOTTOM);
        legend.setOverlay(false);

        chart.setTitleText(chartTitle);
        chart.getTitle().getBody().getXmlObject().getPArray(0).getRArray(0).getRPr().setSz(1400);
        chart.getTitle().getBody().getXmlObject().getPArray(0).getRArray(0).getRPr().setB(false);
        chart.setTitleOverlay(false);
        chart.setAutoTitleDeleted(false);

        // 创建序列,并且设置选中区域
//        CTPieSer ctPieSer = chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0);
////         todo 设置区域颜色未成功
//        int j = 0;
//        for (int i = 0; i < categories.length; i++) {
//            CTDPt dPt = ctPieSer.addNewDPt();
//            STHexBinary3 hex = STHexBinary3.Factory.newInstance();
//            if (j++ >= colorList.size()) {
//                j = 0;
//            }
//            hex.setStringValue(colorList.get(j).getColorContainer().xmlText());
//            dPt.addNewIdx().setVal(i);
////            dPt.addNewSpPr().addNewSolidFill().set(CTPresetColor.Factory.newInstance().setVal(PresetColor.CORNFLOWER_BLUE));
//        }

        CTDLbls ctdLbls = chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).addNewDLbls();
        ctdLbls.addNewShowVal().setVal(false);
        ctdLbls.addNewShowLegendKey().setVal(false);
        //类别名称
        ctdLbls.addNewShowCatName().setVal(false);
        //百分比
        ctdLbls.addNewShowSerName().setVal(false);
        ctdLbls.addNewShowPercent().setVal(false);
        //引导线
        ctdLbls.addNewShowLeaderLines().setVal(true);
//        ctdLbls.addNewLeaderLines().addNewSpPr().addNewLn().setCap(500);
        //分隔符为分行符
        ctdLbls.setSeparator("\n");
        //数据标签内
        ctdLbls.addNewDLblPos().setVal(STDLblPos.OUT_END);
    }

    public static void getLineChart(XWPFChart chart, String chartTitle,
                                    Map<String, LinkedHashMap<String, Double>> groupMap, String align) {
        XDDFChartAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
        XDDFValueAxis leftAxis;
        if (align.equals("LEFT")) {
            leftAxis = chart.createValueAxis(AxisPosition.LEFT);
            if (StringUtils.isBlank(chartTitle)) {
                leftAxis.setVisible(false);
                bottomAxis.setVisible(false);
            }
        } else {
            leftAxis = chart.createValueAxis(AxisPosition.RIGHT);
            leftAxis.setCrosses(AxisCrosses.MAX);
            bottomAxis.setVisible(false);
            bottomAxis.setTickLabelPosition(AxisTickLabelPosition.NONE);
        }
        leftAxis.crossAxis(bottomAxis);
        bottomAxis.crossAxis(leftAxis);
        XDDFLineChartData bar = (XDDFLineChartData) chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);
        int i = 0;
        for (Entry<String, LinkedHashMap<String, Double>> entry : groupMap.entrySet()) {
            Map<String, Double> map = entry.getValue();
            String[] categories = map.keySet().toArray(new String[0]);
            Double[] values = map.values().toArray(new Double[0]);
            int numOfPoints = categories.length;
            String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));
            String valuesDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 1, 1));
            XDDFDataSource<?> categoriesData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange, 0);
            XDDFNumericalDataSource<? extends Number> valuesData = XDDFDataSourcesFactory.fromArray(values, valuesDataRange, 1);
            XDDFLineChartData.Series series = (XDDFLineChartData.Series) bar.addSeries(categoriesData, valuesData);
            series.setTitle(entry.getKey(), null);
            XDDFSolidFillProperties fill = new XDDFSolidFillProperties(colorList.get(i));
            //条形图，填充颜色
            series.setFillProperties(fill);
            i++;
            if (i >= colorList.size()) {
                i = 0;
            } //直线
            series.setSmooth(false);
            //设置标记大小
            series.setMarkerSize((short) 2);
            //添加标签数据，折线图中拐点值展示
            series.setShowLeaderLines(true);
        }
        bar.setVaryColors(varyColors);
        CTPlotArea plotArea = chart.getCTChart().getPlotArea();
        chart.plot(bar);
        for (CTLineChart ctLineChart : plotArea.getLineChartList()) {
            for (CTLineSer ctBarSer : ctLineChart.getSerArray()) {
                ctBarSer.addNewDLbls();
                ctBarSer.getDLbls().addNewDLblPos().setVal(STDLblPos.CTR);
                ctBarSer.getDLbls().addNewShowVal().setVal(true);
                ctBarSer.getDLbls().addNewShowLegendKey().setVal(false);
                ctBarSer.getDLbls().addNewShowCatName().setVal(false);
                ctBarSer.getDLbls().addNewShowSerName().setVal(false);
            }
        }

        XDDFChartLegend legend = chart.getOrAddLegend();
        legend.setPosition(LegendPosition.BOTTOM);
        legend.setOverlay(false);

        if (StringUtils.isNotBlank(chartTitle)) {
            chart.setTitleText(chartTitle);
            chart.getTitle().getBody().getXmlObject().getPArray(0).getRArray(0).getRPr().setB(false);
            chart.setTitleOverlay(false);
            chart.setAutoTitleDeleted(false);
        }
    }
}
